package com.feng.common.model;

public class PageRequest implements Pageable {
    /**
     * 页码 (base 1)
     */
    private int page;
    /**
     * 每页大小
     */
    private int size;

    public PageRequest() {
    }

    public PageRequest(int page, int size) {
        if (page < 1) {
            throw new IllegalArgumentException("Page index must not be less than 1!");
        }
        if (size < 1) {
            throw new IllegalArgumentException("Page size must not be less than one!");
        }
        this.page = page;
        this.size = size;
    }

    @Override
    public int getPage() {
        return this.page > 0 ? this.page : 1;
    }

    @Override
    public int getSize() {
        return this.size > 0 ? this.size : 15;
    }

    @Override
    public long getOffset() {
        return (long) (getPage() - 1) * (long) size;
    }
}
